package org.jeecg.modules.flowable.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.jeecg.modules.flowable.common.dic.ResultMessage;
import org.jeecg.modules.flowable.common.util.json.ObjectConvert;
import org.jeecg.modules.flowable.controller.dto.FlowStartRequest;
import org.jeecg.modules.flowable.controller.dto.MatterRequest;
import org.jeecg.modules.flowable.entity.TActMatterEntity;
import org.jeecg.modules.flowable.service.MatterService;
import org.jeecg.modules.flowable.service.bo.Matter;
import org.jeecg.modules.flowable.service.bo.flow.FlowInst;
import org.jeecg.modules.flowable.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Title:  <br>
 * Desc:  <br>
 * Date: 6/16/22 1:58 PM <br>
 * Company: 联通（辽宁）产业互联网有限公司 <br>
 *
 * @author zxd
 * @version 1.0.0
 */
@Api(value = "MatterManagerController", tags = {"(module-flowable)-事项管理"})
@ApiSort(value = 1)
@RestController
@RequestMapping("/MatterManagerController")
@Slf4j
public class MatterManagerController {

    @Autowired
    private MatterService matterService;

    @RequiresRoles({"admin"})
    @ApiOperation(value = "事项列表", notes = "事项列表")
    @RequestMapping(path = "/queryMatterList", method = RequestMethod.POST)
    @ResponseBody
    public Result<Page<Matter>> queryMatterList(String matterName, String matterType, @RequestParam("pageNo") Integer argCurrPage, @RequestParam("pageSize") Integer argPageSize) {
        Page<Matter> matterPage = matterService.queryMatterList(matterName, matterType, argCurrPage, argPageSize);
        return Result.OK(matterPage);
    }

    @RequiresRoles({"admin"})
    @ApiOperation(value = "保存", notes = "保存")
    @RequestMapping(path = "/save", method = RequestMethod.POST)
    @ResponseBody
    public Result<Matter> save(@RequestBody MatterRequest argMatterRequest) {
        TActMatterEntity convert = ObjectConvert.convert(argMatterRequest, TActMatterEntity.class);
        Matter save = matterService.save(convert);
        return Result.OK(save);
    }

    @RequiresRoles({"admin"})
    @ApiOperation(value = "启动流程", notes = "启动流程")
    @RequestMapping(path = "/flowStart", method = RequestMethod.POST)
    @ResponseBody
    public Result<FlowInst> flowStart(@RequestBody FlowStartRequest argFlowStartRequest) {
        FlowInst flowInst = matterService.flowStart(argFlowStartRequest);
        return Result.OK(flowInst);
    }

    @RequiresRoles({"admin"})
    @ApiOperation(value = "删除事项", notes = "启动流程")
    @RequestMapping(path = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> delete(String argId) {
        matterService.delete(argId);
        return Result.OK(ResultMessage.OK);
    }
}